<template>
  <div class="government-service">
    <el-row :gutter="20">
      <el-col :span="12">
        <div class="grid-content">
          <el-carousel>
            <el-carousel-item v-for="(item, index) in carouselItems" :key="index">
              <img :src="require(`@/assets/images/home/${item}.jpg`)" alt="轮播图">
            </el-carousel-item>
          </el-carousel>
        </div>
        <div class="grid-content">
          <el-card class="notice-card">
            <div slot="header" class="clearfix">
              <span>通知公告</span>
            </div>
            <el-scrollbar style="height: 200px;">
              <div v-for="(notice, index) in notices" :key="index" class="notice-item">
                <span class="notice-date">{{ notice.date }}</span>
                <span class="notice-content">{{ notice.content }}</span>
              </div>
            </el-scrollbar>
          </el-card>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content">
          <el-card class="contact-card">
            <div slot="header" class="clearfix">
              <span>通讯录</span>
            </div>
            <el-input placeholder="请输入你想查找的联系人姓名,或者能力标签" v-model="contactSearch">
              <el-button slot="append" icon="el-icon-search">查找</el-button>
            </el-input>
          </el-card>
        </div>
        <div class="grid-content">
          <el-card class="function-card">
            <div slot="header" class="clearfix">
              <span>功能入口</span>
            </div>
            <div class="function-grid">
              <el-button class="function-btn" type="primary" icon="el-icon-menu" circle></el-button>
              <el-button class="function-btn" type="success" icon="el-icon-document" circle></el-button>
              <el-button class="function-btn" type="warning" icon="el-icon-setting" circle></el-button>
              <el-button class="function-btn" type="danger" icon="el-icon-user" circle></el-button>
              <el-button class="function-btn" type="info" icon="el-icon-message" circle></el-button>
              <el-button class="function-btn" type="primary" icon="el-icon-star-off" circle></el-button>
            </div>
            <div class="function-labels">
              <span>点击这里</span>
              <span>功能入口</span>
              <span>功能入口</span>
              <span>功能入口</span>
              <span>功能入口</span>
              <span>功能入口</span>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col>
        <div class="grid-content">
          <el-card class="task-card">
            <div slot="header" class="clearfix">
              <el-tabs v-model="activeTaskTab">
                <el-tab-pane label="最新客户" name="tracking">
                  <el-row :gutter="20">
                    <el-col :span="6" v-for="(item, index) in list.clientList" :key="index">
                      <el-card class="task-item-card" shadow="hover">
                        <div slot="header" class="task-header">
                          <span class="urgent-tag" v-if="item.urgent">紧急</span>
                          <span class="task-title">{{ item.name }}</span>
                        </div>
                        <div class="task-content">
                          <div class="task-meta">
                            <span><i class="el-icon-user"></i> {{ item.leader }}</span>
                            <span><i class="el-icon-date"></i> {{ item.date }}</span>
                          </div>
                          <el-button type="text" class="task-detail-btn">查看详情</el-button>
                        </div>
                      </el-card>
                    </el-col>
                  </el-row>
                </el-tab-pane>
                <el-tab-pane label=" 最新合同" name="hetong">
                  <el-row :gutter="20">
                    <el-col :span="6" v-for="(item, index) in list.contractList" :key="index">
                      <el-card class="task-item-card" shadow="hover">
                        <div slot="header" class="task-header">
                          <span class="urgent-tag" v-if="item.urgent">紧急</span>
                          <span class="task-title">{{ item.name }}</span>
                        </div>
                        <div class="task-content">
                          <div class="task-meta">
                            <span><i class="el-icon-user"></i> {{ item.leader }}</span>
                            <span><i class="el-icon-date"></i> {{ item.date }}</span>
                          </div>
                          <el-button type="text" class="task-detail-btn">查看详情</el-button>
                        </div>
                      </el-card>
                    </el-col>
                  </el-row>
                </el-tab-pane>
                <el-tab-pane label="最新项目" name="completed">
                  <el-row :gutter="20">
                    <el-col :span="6" v-for="(item, index) in list.projectList" :key="index">
                      <el-card class="task-item-card" shadow="hover">
                        <div slot="header" class="task-header">
                          <span class="urgent-tag" v-if="item.urgent">紧急</span>
                          <span class="task-title">{{ item.name }}</span>
                        </div>
                        <div class="task-content">
                          <div class="task-meta">
                            <span><i class="el-icon-user"></i> {{ item.leader }}</span>
                            <span><i class="el-icon-date"></i> {{ item.date }}</span>
                          </div>
                          <el-button type="text" class="task-detail-btn">查看详情</el-button>
                        </div>
                      </el-card>
                    </el-col>
                  </el-row>
                </el-tab-pane>
              </el-tabs>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import indexApi from '@/api/index'

export default {
  name: 'GovernmentService',
  data() {
    return {
      activeTaskTab: 'tracking',
      contactSearch: '',
      carouselItems: ['1', '2', '3', '4'],
      list: {},
      notices: [
        {
          title: '这是—条通知公告标题标题',
          date: '2019-08-01',
          content: '这条通知公告内容这—条通知公...'
        },
      ],

    }
  },
  methods: {
    async getHomeInfo() {
      try {
        const response = await indexApi.getHomeInfo()
        this.info = response.data.info
        this.list = {
          clientList: response.data.list?.clientList || [],
          contractList: response.data.list?.contractList || [],
          projectList: response.data.list?.projectList || []
        }
      } catch (error) {
        this.$message.error('获取数据失败：' + error.message)
      }
    },
  },
  created() {
    this.getHomeInfo()
  }
}
</script>

<style scoped>
.government-service {
  font-family: 'Microsoft YaHei', sans-serif;
  color: #333;
}

.el-row {
  margin-bottom: 20px;
}

.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
  margin-bottom: 20px;
}

.notice-card,
.task-card,
.contact-card,
.function-card {
  margin-bottom: 20px;
}

.notice-item {
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.notice-item:last-child {
  border-bottom: none;
}

.notice-date {
  color: #999;
  font-size: 12px;
  margin: 5px 0;
}

.notice-content {
  color: #666;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.function-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-bottom: 10px;
}

.function-btn {
  margin: 5px;
  width: 50px;
  height: 50px;
  font-size: 20px;
}

.function-labels {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.function-labels span {
  display: inline-block;
  width: 50px;
  margin: 5px;
  text-align: center;
  font-size: 12px;
  color: #666;
}

.urgent-tag {
  background-color: #f56c6c;
  color: white;
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 12px;
  margin-right: 5px;
}

.task-header {
  display: flex;
  align-items: center;
}

.task-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-content {
  padding: 10px 0;
}

.task-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 12px;
  color: #999;
}

.task-detail-btn {
  width: 100%;
  text-align: center;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
</style>